/*
 * @Date: 2024-03-29 20:19:08
 * @LastEditors: 玄绮 shijiahansi@qq.com
 * @LastEditTime: 2024-04-13 13:05:50
 * @FilePath: \server\src\common\System.cpp
 */
#include "System.h"

#include "console/utf8_console.h"
#include <boost/locale.hpp>

using namespace boost::locale;

namespace sys {

    std::string convertToUTF8(const std::string& input) {
        return boost::locale::conv::to_utf<char>(input, "GBK");
    }

    std::string convertToGBK(const std::string& input) {
        return boost::locale::conv::from_utf<char>(input, "GBK");
    }

    std::string to_local(std::string str) {
#ifdef _WIN32
        return boost::locale::conv::from_utf<char>(str, "GBK");
#else
        return str;
#endif
    }

    std::string from_local(std::string str) {
#ifdef _WIN32
        return boost::locale::conv::to_utf<char>(str, "GBK");
#else
        return str;
#endif
    }

    std::wstring encode(std::string str, const std::string& charset) {
        return conv::to_utf<wchar_t>(str, charset);
    }

    std::string decode(std::wstring wstr, const std::string& charset) {
        return conv::from_utf(wstr, charset);
    }

    void InitConsole(void) {
        init_utf8_console();
    }
}  // namespace sys
